package org.se.lab;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class Mail {

	private String address;
	private static final Logger logger = LoggerFactory.getLogger(Mail.class);

	public Mail(String address, User owner) {
		setAddress(address);
		setOwner(owner);
	}

	public Mail(String address) {
		setAddress(address);;
	}

	public String getAddress() {
		return address;
	}

	public void setAddress(String address) {
		if (address == null)
			throw new IllegalArgumentException();
		this.address = address;
		logger.info("Address = "+address);
	}

	/*
	 * Association [1]
	 */

	private User owner;

	public User getOwner() {
		return owner;
	}

	public void setOwner(User owner) {
		if (owner == null)
			throw new IllegalArgumentException();
		this.owner = owner;
		logger.info("Owner = "+ owner);
	}

	@Override
	public String toString() {
		return "Mail [address=" + address + ", owner=" + owner + "]";
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((address == null) ? 0 : address.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Mail other = (Mail) obj;
		if (address == null) {
			if (other.address != null)
				return false;
		} else if (!address.equals(other.address))
			return false;
		return true;
	}

}
